﻿using Common.Interfaces;

namespace Domain.Permissions.ValueObjects
{
    public class Permission : ValueObject
    {
        private Permission( string permissionName, string sign, string? description) 
        {
            this.PermissionName = permissionName;
            this.Description = description;
            this.PermissionSign = sign;
        }

        /// <summary>
        /// 创建权限值对象
        /// </summary>
        /// <param name="permissionName"></param>
        /// <param name="sign"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static Permission Create(string permissionName, string sign, string? description = null)
        {
            if (string.IsNullOrEmpty(permissionName))
                throw new ArgumentException("权限名不能为空");

            if (string.IsNullOrEmpty(sign))
                throw new ArgumentException("权限标志不能为空");

            return new(permissionName, sign, description);
        }

        protected override IEnumerable<object> GetEqualityComponents()
        {
            yield return PermissionName;
            yield return PermissionSign;
            yield return Description ?? string.Empty;
        }

        /// <summary>
        /// 权限名称
        /// </summary>
        public string PermissionName { get; set; }

        /// <summary>
        /// 权限描述
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 权限标识 验证时需要进行对比
        /// </summary>
        public string PermissionSign { get; set; }
    }
}
